<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>LkScript</title>
		<script src="https://unpkg.com/codeflask/build/codeflask.min.js"></script>
		<style>
			.code {
				position: relative;
				width: 500px;
				height: 300px;
				overflow: hidden;
				border: solid #eee 1px;
			}
			textarea::selection {
				background-color: green;
			}
		</style>
	</head>
	<body>
		<div class="code" id="editor"></div>
		<div class="bg"></div>
		<script>
			const editorElem = document.getElementById("editor");
			const flask = new CodeFlask(editorElem, {
				language: "js",
				lineNumbers: true,
			});
			flask.updateCode('const my_new_code_here = "Blabla"');

			flask.onUpdate((code) => {
				// do something with code here.
				// this will trigger whenever the code
				// in the editor changes.
				try {
					const fun = new Function("a", "b", code);
					console.log("==> fun", fun(1, 3));
				} catch (error) {
					console.log("error");
				}
			});
		</script>
	</body>
</html>
